﻿using System.Collections.Specialized;
using System.Configuration;
using SpiderCore.Utility;

namespace SpiderCore.Spiders
{
    /// <summary>
    /// 母蜘蛛
    /// </summary>
    internal class SpiderMother
    {
      
        private static SpiderMother _spiderMother;
        private static readonly  object _syncBoot=new object();
        private SpiderMother()
        {
            
        }
        public static SpiderMother GetInstance()
        {
            if (_spiderMother == null)
            {
                lock (_syncBoot)
                {
                    if (_spiderMother == null)
                    {
                        _spiderMother = new SpiderMother();
                    }
                }
            }
            return _spiderMother;
        }
        /// <summary>
        /// 生产一个蜘蛛
        /// </summary>
        /// <returns></returns>
        public SpiderCore.Spiders.Spider CreateSprider(string route)
        {
            NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("SpiderRoute/Spider");
            string path = config[route];
            var ret = ReflectionHelper.CreateInstance<SpiderCore.Spiders.Spider>(path);
            return ret;
        }
       
    }
}
